package cn.xfdzx.android.apps.shop.presenter;

import java.util.HashMap;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.IdCardBeen;
import cn.xfdzx.android.apps.shop.bean.LicenseImgBeen;
import cn.xfdzx.android.apps.shop.bean.Ruzhu_StepBean;
import cn.xfdzx.android.apps.shop.bean.Store_ruzhuBean;
import cn.xfdzx.android.apps.shop.contract.Store_InfoContract;
import cn.xfdzx.android.apps.shop.model.Store_InfoModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * author : hjl
 * date   : 2021/6/3
 * desc   :
 * version:
 */
public class Store_InfoPresenter extends BasePresenter<Store_InfoContract.View> implements Store_InfoContract.Presenter {
    private Store_InfoContract.Model model;

    public Store_InfoPresenter() {
        model = new Store_InfoModel();
    }

    @Override
    public void getState_Ruzhu(HashMap<String, Object> map) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getRuzhuState(map)
                .compose(RxScheduler.<Store_ruzhuBean>Flo_io_main())
                .as(mView.<Store_ruzhuBean>bindAutoDispose())
                .subscribe(new Consumer<Store_ruzhuBean>() {
                    @Override
                    public void accept(Store_ruzhuBean bean) throws Exception {
                        mView.getStateType(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getStep_Ruzhu(String s) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getStepRuzhu(s)
                .compose(RxScheduler.<Ruzhu_StepBean>Flo_io_main())
                .as(mView.<Ruzhu_StepBean>bindAutoDispose())
                .subscribe(new Consumer<Ruzhu_StepBean>() {
                    @Override
                    public void accept(Ruzhu_StepBean bean) throws Exception {
                        mView.getRuzhuStep(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
    @Override
    public void licenseImg(String licenseImg) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.licenseImg(licenseImg)
                .compose(RxScheduler.<LicenseImgBeen>Flo_io_main())
                .as(mView.<LicenseImgBeen>bindAutoDispose())
                .subscribe(new Consumer<LicenseImgBeen>() {
                    @Override
                    public void accept(LicenseImgBeen bean) throws Exception {
                        mView.oneLicenseImgSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void idCardSubmit(String infoImg, String emblemImg) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.idCardSubmit(infoImg,emblemImg)
                .compose(RxScheduler.<IdCardBeen>Flo_io_main())
                .as(mView.<IdCardBeen>bindAutoDispose())
                .subscribe(new Consumer<IdCardBeen>() {
                    @Override
                    public void accept(IdCardBeen bean) throws Exception {
                        mView.onIdCardSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void onIdCardSuccessguanli(String infoImg, String emblemImg) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.idCardSubmit(infoImg,emblemImg)
                .compose(RxScheduler.<IdCardBeen>Flo_io_main())
                .as(mView.<IdCardBeen>bindAutoDispose())
                .subscribe(new Consumer<IdCardBeen>() {
                    @Override
                    public void accept(IdCardBeen bean) throws Exception {
                        mView.onIdCardSuccessguanli(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
